# -*- python -*-
# ex: set syntax=python:

c = BuildmasterConfig = {}


####### BUILDSLAVES

from buildbot.buildslave import BuildSlave
c['slaves'] = [BuildSlave('bot1name', 'bot1pazzwd'),  # ?!?
               BuildSlave('bot4name', 'bot4pazzwd'),
               BuildSlave('bot8name', 'bot8pazzwd'),
               BuildSlave('bot9name', 'bot9pazzwd'),
               BuildSlave('vm42-m3', 'bot5pazzwd', max_builds=1), # linux-builder + valgrind
               BuildSlave('vm43-m3', 'bot6pazzwd', max_builds=2), # linux-small, linux-pin, jtsan
               BuildSlave('vm630-m3', 'bot7pazzwd'), # Mac 10.6
               BuildSlave('vm44-m3', '306a4c6fd78d37ddb78'), # full-linux
               BuildSlave('vm10-m3', 'bot2pazzwd'),   # XP
               BuildSlave('vm50-m3', 'bot3pazzwd'),   # Vista
               BuildSlave('vm51-m3', 'bot3pazzwd'),   # Win7
               BuildSlave('vm45-m3', 'kzvvnr'),                # llvm
               BuildSlave('chromeperf01', '8119386db13beb1b'), # perf-win
               BuildSlave('chromeperf05', '8119386db13beb1b')] # perf-linux

# to limit to two concurrent builds on a slave, use
#  c['slaves'] = [BuildSlave('bot1name', 'bot1passwd', max_builds=2)]

# 'slavePortnum' defines the TCP port to listen on. This must match the value
# configured into the buildslaves (with their --master option)
c['slavePortnum'] = 9989

# Keep more logs than the default setup suggests
c['buildHorizon']   = 4000
c['logHorizon']     = 1000
c['buildCacheSize'] = 400

####### CHANGESOURCES

settings = {
    'svnurl':  'http://data-race-test.googlecode.com/svn/trunk',
}

from buildbot.changes.svnpoller import SVNPoller
svn_poller = SVNPoller(
                   svnurl=settings['svnurl'],
                   pollinterval=60, # seconds
                   histmax=10,
                   svnbin='/usr/bin/svn')

c['sources'] = [ svn_poller ]



####### BUILDERS

# reload the common module
import common
reload(common)

import builder_linux
import builder_linux_small
import builder_windows
import builder_linux_pin
import builder_mac
import builder_experimental
import builder_valgrind
import builder_linux_build
import builder_jtsan_red
import builder_llvm

c['builders'] = []

for module in [builder_valgrind,
               builder_linux_build,
               builder_linux_small,
               builder_linux,
               builder_linux_pin,
               builder_windows,
               builder_mac,
               builder_experimental,
               builder_jtsan_red,
               builder_llvm]:
  reload(module)
  c['builders'].extend(module.generate(settings))


####### SCHEDULERS

from buildbot.scheduler import Scheduler
from buildbot.scheduler import Dependent
from buildbot.scheduler import Nightly

commonBuilderNames    = ['buildbot-winxp',
                         'buildbot-vista',
                         'buildbot-win7',
                         'buildbot-mac',
                         'buildbot-jtsan-red',
                         'buildbot-llvm',
                         'perf-win',
                         'perf-linux']
dependentBuilderNames = ['linux',
                         'buildbot-linux-small',
                         'buildbot-linux-pin']

# Failures on these bots will be e-mailed.
# TODO: make other bots less flaky and add them here.
stableBuilderNames    = ['buildbot-valgrind',
                         'buildbot-linux-build',
                         'buildbot-linux-small',
                         'linux',
#                         'buildbot-linux-pin',
                         'buildbot-winxp',
                         'buildbot-vista',
                         'buildbot-win7',
                         'perf-win',
                         'perf-linux',
                         ]
periodicBuilderNames = commonBuilderNames + dependentBuilderNames

sched_common = Scheduler(name='common', branch=None,
                         treeStableTimer=10,
                         builderNames=commonBuilderNames)
sched_valgrind = Scheduler(name='valgrind', branch=None,
                        treeStableTimer=10,
                        builderNames=['buildbot-valgrind'])
sched_build = Dependent(name='build',
                        upstream=sched_valgrind,
                        builderNames=['buildbot-linux-build'])
sched_tests = Dependent(name='tests',
                        upstream=sched_build,
                        builderNames=dependentBuilderNames)
sched_nightly = Nightly(name="nightly",
                        hour=22, minute=0,  # 10pm PDT
                        builderNames=periodicBuilderNames)

c['schedulers'] = [sched_common,
                   sched_valgrind,
                   sched_build,
                   sched_tests,
                   sched_nightly]



####### STATUS TARGETS

c['status'] = []

from buildbot.status import html
c['status'].append(html.WebStatus(http_port=8010,allowForce=False))
c['status'].append(html.WebStatus(http_port=8011,allowForce=True))

from buildbot.status.mail import MailNotifier
c['status'].append(MailNotifier(fromaddr="timurrrr+tsan+buildbot@gmail.com",
                   lookup="gmail.com", # add @gmail.com if "@" is not in the commiter's ID
                   extraRecipients=['data-race-test@googlegroups.com'],
                   builders=stableBuilderNames,
                   mode='problem'))

####### PROJECT IDENTITY

c['projectName'] = 'ThreadSanitizer'
c['projectURL'] = 'http://code.google.com/p/data-race-test'
c['buildbotURL'] = 'http://build.chromium.org/p/client.tsan/'
